﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Linq;
using System.Web;

namespace Gollie.DataTables
{
	public class BaseBindable<T> : List<T>
	{
		public List<T> Sort(string property, bool asc)
		{
			PropertyInfo col = typeof(T).GetProperty(property);
			if (asc)
			{
				return this.OrderBy(item => col.GetValue(item, null)).ToList();
			}
			return this.OrderByDescending(item => col.GetValue(item, null)).ToList();
		}

		public object GetDynamicSortProperty(object item, string propName)
		{
			//Use reflection to get order type
			return item.GetType().GetProperty(propName).GetValue(item, null);
		}

		public List<T> Filter(Predicate<T> predicate)
		{
			return this.Where(item => predicate(item)).ToList();
		}
	}
}